<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>策略模式</title>
    <script type="text/javascript">
        const wholeOrDept  = ["all","single"];
        const mainOrAssist = ["main","assist"];
        const progressType = ["task","dept","type"];//任务进展 单位进展，类型进展
        const latitude = ["count","latitude"];//维度
        const reqType = [0,1,2,3,4,5] //任务进展(2,3) 单位进展(1,2)，类型进展(4,5)
        const config = {}
        const Strategy = function (pattern) {
            this.maintask = function () {  //主责-任务进展
                console.log("主责-任务进展")
                return {fun:"progressLatitude",reqType:2,tabType:1,config:config,currentTaskType:{}}
            }
            this.assisttask = function () {//协作-任务进展
                console.log("协作-任务进展")
                return {fun:"progressLatitude",reqType:3,tabType:1,config:config,currentTaskType:{}}
            }
            this.maintype = function () {//主责-类型进展
                console.log("主责-类型进展")
                return {fun:"progressLatitude",reqType:4,tabType:3,config:config}
            }
            this.assisttype = function () {//协作-类型进展
                console.log("协作-类型进展")
                return {fun:"progressLatitude",reqType:5,tabType:5,config:config}
            }
            this.allmaindept = function () { //全部-主责-部门进展
                console.log("全部-主责-部门进展")
                return {fun:"progressLatitude",reqType:0,tabType:2,config:config,typeId:0}
            }
            this.allassistdept = function () { //全部-协作-部门进展
                console.log("全部-协作-部门进展")
                return {fun:"progressLatitude",reqType:1,tabType:2,config:config,typeId:1}
            }
            this.singlemaindept = function () { //单位-主责-部门进展
                console.log("单位-主责-部门进展")
                return {fun:"progressLatitude",reqType:0,tabType:2,config:config,typeId:0}
            }
            this.singleassistdept = function () { //单位-协作-部门进展
                console.log("单位-协作-部门进展")
                return {fun:"progressLatitude",reqType:0,tabType:2,config:config,typeId:0}
            }
            /**
             * 添加规则
             * @param pattern
             * @param rulesResult
             */
            this.addStrategy = function (pattern,rulesResult) {
                this[pattern] = rulesResult
            }
            /**
             * 获取规则结果
             * @param pattern
             * @returns {*}
             */
            this.getStrategy = function (pattern) {
                console.log("===============pattern=========",pattern)
                if (this[pattern]) {
                    return this[pattern].call()
                } else {
                    return `${pattern}该方法未定义！！！`
                }

            }
        }
        //规则如下
        const strategy = new Strategy()
        console.log(strategy.getStrategy(`${wholeOrDept[0]}${mainOrAssist[1]}${progressType[3]}`))
        //定义新规则
        strategy.addStrategy(`countallmain`,()=>{ //数量-全部部门-主责
            return {fun:"getMainDept",config:config}
        })
        console.log(strategy.getStrategy(`countallmain`))
    </script>
</head>
<body>

</body>
</html>
